//
//  HelpingViewController.swift
//  FeastBooking
//
//  Created by Imon on 2017/12/5.
//  Copyright © 2017年 Imon. All rights reserved.
//

import UIKit

class HelpingViewController: UIViewController {
    
    let supportView: SupportView = {
        let supportView = SupportView()
        return supportView
    }()
    
    let questionLabels: [UILabel] = {
        var labels:[UILabel] = []
        for i in 1...numOfQuestion {
            let label = UILabel()
            label.font = AppFont(size: 13)
            label.numberOfLines = 0
            label.textColor = proceededColor
            label.text = LanguageHelper.getString(key: "QUESTION\(i)")
            labels.append(label)
        }
        return labels
    }()
    
    let answerLabels: [UILabel] = {
        var labels:[UILabel] = []
        for i in 1...numOfQuestion {
            let label = UILabel()
            label.font = AppFont(size: 13)
            label.numberOfLines = 0
            label.textColor = UIColor.gray
            label.text = LanguageHelper.getString(key: "ANSWER\(i)")
            labels.append(label)
        }
        return labels
    }()
    
    var scrollView: UIScrollView?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.navigationItem.title = LanguageHelper.getString(key: "COMMON_ISSUE")
        setBackBarItem()
        
        let supportHeight: CGFloat = 40
        let leading: CGFloat = 10
        let topGap: CGFloat = 10
        
        scrollView = UIScrollView()
        scrollView?.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height - supportHeight)
        scrollView?.showsVerticalScrollIndicator = false
        scrollView?.showsHorizontalScrollIndicator = false
        scrollView?.isScrollEnabled = true
        scrollView?.alwaysBounceVertical = true
        scrollView?.autoresizingMask = UIViewAutoresizing.flexibleHeight
        
        let textMaxSize = CGSize(width: self.view.bounds.width - 2 * leading, height: 1/0.0)
        var currentY = topGap
        for i in 0...questionLabels.count - 1 {
            let questionSize = TextSize.textSize(text: questionLabels[i].text!, font: questionLabels[i].font, maxSize: textMaxSize)
            questionLabels[i].frame = CGRect(x: leading, y: currentY, width: questionSize.width, height: questionSize.height)
            currentY += (questionSize.height + topGap)
            let answerSize = TextSize.textSize(text: answerLabels[i].text!, font: answerLabels[i].font, maxSize: textMaxSize)
            answerLabels[i].frame = CGRect(x: leading, y: currentY, width: answerSize.width, height: answerSize.height)
            currentY += (answerSize.height + topGap)
            scrollView?.addSubview(questionLabels[i])
            scrollView?.addSubview(answerLabels[i])
        }
        
        scrollView?.contentSize = CGSize(width: self.view.bounds.width, height: currentY)
        
        supportView.frame = CGRect(x: 0, y: self.view.bounds.height - supportHeight - 64, width: self.view.bounds.width, height: supportHeight)
        supportView.layoutSubviews()
        self.view.addSubview(supportView)
        self.view.addSubview(scrollView!)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
